//
//  PasswordLogin.m
//  ArtCircle
//
//  Created by sunbin on 2017/5/19.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "PasswordLogin.h"
#import "Registration.h"

@interface PasswordLogin ()
@property (nonatomic ,strong) TwoInputBox *two;
@end

@implementation PasswordLogin


-(void)viewWillAppear:(BOOL)animated{

    [self pushAndPop:[[Registration alloc] init] range:NSMakeRange(1, 2)];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.title = @"密码登录";
    
    _two = self.contentView.inputBoxView.two;
    
    _two.account.text = _account;
    _two.pwd.placeholder = @"请输入登录密码";
    
    [_two.configBtn setTitle:@"进入艺圈人" forState:UIControlStateNormal];
    _two.bottomView.hidden = YES;
    
    
    
    WEAKSELF;
#pragma make 密码登录 登陆成功+环信登录 +跳转
    _two.nextStepHandler = ^(NSString *account, NSString *pwd, NSInteger make ,UIButton*sender) {

        [weakSelf.navigationController.view showLoading:@"正在登录"];
        
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [weakSelf.navigationController.view hideHUD];
            
            [[AccountManage sharedAccountManage] request:Send apiTy:API_PassWordLogin params:@{@"phone":account,@"password":pwd} success:^(NSDictionary *results, NSString *successMsg) {
                                
                //环信登录
              [[EaseMobManage sharedEaseMobManage]
               loginWithUsername:IF_NULL_TO_STRING([results objectForKey:@"id"])
               password         :IF_NULL_TO_STRING([results objectForKey:@"hxPsw"]) success:^(NSString *successMsg) {
#pragma make 登录成功 跳转 保存数据
                  
                  [weakSelf PasswordLoginCompleDataSaveAccount:account pwd:pwd uid:IF_NULL_TO_STRING([results objectForKey:@"id"]) data:results];
                  
                  
                  ESTabBarController *main = [MainViewController bounceBarItems];
                  [weakSelf presentViewController:main animated:YES completion:^{
                      [main.navigationController.view showSuccess:@"登录成功"];
                  }];

                  
              } failed:^(NSString *msg) {
                  
              }];
            } failed:^(WrapperEnumError errorty, NSString *msg) {
                
            }];
        });

        
        
    };
}


- (BOOL)isShowAuthorizedLoginView {
    return YES;
}

- (BOOL)isShowAccountHeaderView {
    return YES;
}

- (InputBoxType)getInputBoxType {
    return InputBoxTypeTwo;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
